package com.ldtechnologies.springapp.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ldtechnologies.springapp.service.ProductManager;

@Controller
public class InventaryController {
	protected final Log logger = LogFactory.getLog(getClass());
	
	@Autowired
	private ProductManager pManager;

	@RequestMapping(value="/helloInventary.htm")
	public ModelAndView handleRequest( HttpServletRequest request 
									 , HttpServlet response )
									   throws IOException, ServletException{
		
		ModelAndView mv = new ModelAndView("helloInventary");
		
		Map<String, Object> modelo = new HashMap<String, Object>();
		modelo.put("now", (new Date() ).toString() );
		modelo.put("products", this.pManager.getProducts());
		
		mv.addObject("model", modelo);
		return mv;
	}
	
	public ProductManager getpManager() {
		return pManager;
	}

	public void setpManager(ProductManager pManager) {
		this.pManager = pManager;
	}
	
	
}
